package com.itcast.quartz.job;

import org.quartz.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static com.itcast.quartz.DateAndTimeUtils.dateConvertToLocalDateTime;

public class HelloJobTrigger implements Job {
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //输出当前时间
        LocalDateTime date = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String dataStr = date.format(formatter);

        //获取jobKey、startTime、endTime
        Trigger trigger = context.getTrigger();
        System.out.println("jobKey的名称："+trigger.getJobKey().getName());
        System.out.println("jobKey的组名："+trigger.getJobKey().getGroup());

        System.out.println("任务开始时间："+trigger.getStartTime());
        dateConvertToLocalDateTime(trigger.getStartTime()).format(formatter);
        System.out.println("任务结束时间："+trigger.getEndTime());

    }
}
